﻿using Microsoft.AspNetCore.Mvc;
using NFine.Data.Dto.WeixinManage;
using NFine.Data.Entity.SystemManage;
using NFine.Service.WeixinManage;
using NFine.Util;

namespace NFine.Web.Areas.WeiXinManage.Controllers
{
    [Area("WeiXinManage")]
    public class WxHomeController : Controller
    {
        WxAccountService wxAccountService = new WxAccountService();

        [HttpGet]
        public ActionResult Index(string keyValue)
        {
            WxAccountOutputDto wxAccountOutputDto = wxAccountService.GetForm(keyValue);
            OperatorModel operatorModel = OperatorProvider.Provider.GetOperator();
            if (operatorModel.WxAccountModel == null) {
                operatorModel.WxAccountModel = new WxAccountModel();
            }
            operatorModel.WxAccountModel.AppId = wxAccountOutputDto.AppId;
            operatorModel.WxAccountModel.AppName = wxAccountOutputDto.AppName;
            operatorModel.WxAccountModel.AppSecret = wxAccountOutputDto.AppSecret;
            operatorModel.WxAccountModel.AppType = wxAccountOutputDto.AppType;
            OperatorProvider.Provider.AddOperator(operatorModel);
            ViewData["AppName"] = wxAccountOutputDto.AppName;
            return View();
        }

        [HttpGet]
        public ActionResult Default()
        {
            return View();
        }
    }
}